// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由

import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/components/SubCategory.vue'
import ProductDetails from '@/views/Details/index.vue'
import ShoppingCart from '@/views/ShoppingCart/index.vue'
import OrderForm from '@/views/OrderForm/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/indexBack.vue'
import My from '@/views/My/index.vue'
import MyInfo from '@/components/MyComponents/MyInfo.vue'
import MyOrder from '@/components/MyComponents/MyOrder.vue'
import NotFound from '@/views/NotFound.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        { path: '', component: Home },
        { path: 'category/:id', component: Category },
        { path: 'SubCategory/:id', component: SubCategory },
        { path: 'ProductDetails/:id', component: ProductDetails },
        { path: '/cart', component: ShoppingCart },
        { path: '/order', component: OrderForm },
        { path: '/pay', component: Pay },
        { path: '/paycallback', component: PayBack },
        {
          path: '/my',
          component: My,
          children: [
            { path: '', component: MyInfo },
            { path: 'order', component: MyOrder },
          ],
        },
        { path: '/:pathMatch(.*)', component: NotFound },
      ],
    },
    { path: '/login', component: Login },
  ],
  scrollBehavior() {
    return {
      top: 0,
    }
  },
})

export default router
